<?php


namespace app\sapi\controller\v1;


use app\common\controller\Api;
use app\common\model\UserWithdrawalLog;
use app\common\model\User;
use think\Db;

class Withdrawal extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function withdrawal()
    {
        $this->error('系统升级中，敬请期待~');
        $wallet = input('money', 0);
        $user = User::get($this->auth->id);
        if (empty($user) || $user->status != 'normal' || $wallet > $user->money) {
            $this->error('余额不足');
        }
        if (!$user->mobile) $this->error('请先绑定店铺');
        $shop = Db::name('shop')->where('phone="'.$user->mobile.'"')->find();
        if (!$shop) $this->error('请先绑定店铺手机号');
        if ($wallet>=500) $this->error('单次提现不能超过500元');
        $extend['withdrawal_no'] = $this->generateNo(['biz_tag'=>'withdrawal_no','len'=>12,'int_prefix'=>5]);
        $extend['card_no'] = $shop['phone'];
        $res = UserWithdrawalLog::addLog($user, $wallet,$extend);
        if ($res) $this->success('提交成功，请等待审核');
        $this->error('提交失败');
    }

}